home *** CD-ROM | disk | FTP | other *** search
- #ifndef _GLOBALS_
- #define _GLOBALS_
-
- /****************************************************************
-
- HEADER: globals
-
- PURPOSE: For 68K compilers, a register is used to reference
- global variables. This header file helps in two
- ways.
-
- 1. We hide the SetA5 stuff using the macros below
- so that if we compile as a code resource, we
- can just change the macros and things will be ok
- for a4 code.
-
- 2. Since different compilers use different
- ways of setting up a4 for code resources, we
- can hide that here.
-
- AUTHORS: Bill Hubauer (BH)
-
- HISTORY:
- WHEN WHO WHAT
- ---- --- ----
- 1/95 BH Created for application support only.
- 8/95 BH Added support for a4
- 9/95 BH Added Symantec Support
-
- ****************************************************************/
-
- /**
- First, initialize macros (these defaults are ok for PPC)
- **/
-
- #undef __G_A5__
- #undef __G_A4__
- #define SET_GLOBALS(value)
- #define GET_GLOBALS() (0)
- #define EnterGlobals()
- #define ExitGlobals()
- #define RememberCallbackGlobals()
- #define UseCallbackGlobals()
- #define UnuseCallbackGlobals()
- /***
- Next, determine the global reference
- ***/
-
- #ifdef __MWERKS__
- #if __MC68K__
- #if __A5__
- #define __G_A5__
- #else
- #define __G_A4__
- #endif
- #endif
- #else
- #ifdef __SC__
- #if __A4_GLOBALS__
- #define __G_A4__
- #else
- #define __G_A5__
- #endif
- #else
- #ifdef THINK_C
- #if __option(a4_globals)
- #define __G_A4__
- #else
- #define __G_A5__
- #endif
- #else
- #error unsupported compiler
- #endif /* THINK_C */
- #endif /* __SC__ */
- #endif /* __MWERKS__ */
-
-
- /** Next, we define the macros based on globals type
- remember, that neither of the global types are define
- for power pc
- ***/
-
- #ifdef __G_A5__
- #undef GET_GLOBALS
- #undef SET_GLOBALS
- #define GET_GLOBALS() GetA5()
- #define SET_GLOBALS(value) SetA5(value)
- #else
- #ifdef __G_A4__
- #undef GET_GLOBALS
- #undef SET_GLOBALS
- #undef EnterGlobals
- #undef ExitGlobals
- #undef RememberCallbackGlobals
- #undef UseCallbackGlobals
- #undef UnuseCallbackGlobals
-
- #define GET_GLOBALS() _GetA4()
- #define SET_GLOBALS(value) _SetA4(value)
- #define EnterGlobals() EnterCodeResource()
- #define ExitGlobals() ExitCodeResource()
- #define RememberCallbackGlobals() RememberA4()
- #define UseCallbackGlobals() long oldA4 = SetUpA4()
- #define UnuseCallbackGlobals() RestoreA4(oldA4)
-
-
- #endif /* a4 */
- #endif /* a5 */
-
-
- /** now, since _GetA4 , _SetA4 and GetA5 are not standard, we need to define these
- based on compiler
- **/
-
- #ifdef __MWERKS__
- #if __MC68K__
- #include "AsmHelpers.h"
- #include <a4stuff.h>
- #include <setupa4.h>
- #endif
- #else
- #ifdef THINK_C
- static long _GetA4()
- {
- asm{
- move.l a4,d0
- }
- }
-
- #define _SetA4(value) asm{move.l value,a4}
-
- static long GetA5()
- {
- asm{
- move.l a5,d0
- }
- }
-
- #else
- #ifdef __SC__
-
- #pragma parameter __D0 _GetA4
- static long _GetA4();
-
- #pragma parameter __D0 GetA5
- static long GetA5();
-
- #pragma parameter _SetA4(__A0)
- static void _SetA4(long value);
-
- static long _GetA4()
- {
- asm(
- 0x200C, // MOVE.L A4,D0
- 0x4E75 // RTS
- );
- return 0;
- }
-
- static long GetA5()
- {
- asm(
- 0x200D, // MOVE.L A5,D0
- 0x4E75 // RTS
- );
- return 0;
- }
-
-
- static void _SetA4(long value)
- {
- asm(0x2848); // MOVE.L A0,A4
- }
-
-
- #endif
- #endif
- #endif
-
-
-
- #ifdef __cplusplus
-
- // AHHHH you can only use this if direct destruction pref is ON
- // otherwise, MW will try to "register" the destructor with
- // the exception manager, which uses globals, before globals are set up.
-
- /*
- class EnsureGlobals
- {
- public:
- EnsureGlobals(long globals)
- {
- _globals = GET_GLOBALS();
- SET_GLOBALS(globals);
- }
- ~EnsureGlobals()
- {
- SET_GLOBALS(_globals);
- }
- private:
- long _globals;
- };
- */
-
- #endif
-
- #endif
-
-